<?php

class Skjb_Search_Xapian_Database
{
    public $_cPtr=null;

    function add_database($database) {
        Database_add_database($this->_cPtr,$database);
    }

    function __construct($path_or_other=null) {
        switch (func_num_args()) {
        case 0: $r=new_Database(); break;
        default: $r=new_Database($path_or_other);
        }
        $this->_cPtr=$r;
    }

    function reopen() {
        Database_reopen($this->_cPtr);
    }

    function get_description() {
        return Database_get_description($this->_cPtr);
    }

    function postlist_begin($tname) {
        $r=Database_postlist_begin($this->_cPtr,$tname);
        return is_resource($r) ? new Skjb_Search_Xapian_PostingIterator($r) : $r;
    }

    function postlist_end($tname) {
        $r=Database_postlist_end($this->_cPtr,$tname);
        return is_resource($r) ? new Skjb_Search_Xapian_PostingIterator($r) : $r;
    }

    function termlist_begin($did) {
        $r=Database_termlist_begin($this->_cPtr,$did);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function termlist_end($did) {
        $r=Database_termlist_end($this->_cPtr,$did);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function positionlist_begin($did,$tname) {
        $r=Database_positionlist_begin($this->_cPtr,$did,$tname);
        return is_resource($r) ? new Skjb_Search_Xapian_PositionIterator($r) : $r;
    }

    function positionlist_end($did,$tname) {
        $r=Database_positionlist_end($this->_cPtr,$did,$tname);
        return is_resource($r) ? new Skjb_Search_Xapian_PositionIterator($r) : $r;
    }

    function allterms_begin($prefix=null) {
        switch (func_num_args()) {
        case 0: $r=Database_allterms_begin($this->_cPtr); break;
        default: $r=Database_allterms_begin($this->_cPtr,$prefix);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function allterms_end($prefix=null) {
        switch (func_num_args()) {
        case 0: $r=Database_allterms_end($this->_cPtr); break;
        default: $r=Database_allterms_end($this->_cPtr,$prefix);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function get_doccount() {
        return Database_get_doccount($this->_cPtr);
    }

    function get_lastdocid() {
        return Database_get_lastdocid($this->_cPtr);
    }

    function get_avlength() {
        return Database_get_avlength($this->_cPtr);
    }

    function get_termfreq($tname) {
        return Database_get_termfreq($this->_cPtr,$tname);
    }

    function term_exists($tname) {
        return Database_term_exists($this->_cPtr,$tname);
    }

    function get_collection_freq($tname) {
        return Database_get_collection_freq($this->_cPtr,$tname);
    }

    function get_doclength($docid) {
        return Database_get_doclength($this->_cPtr,$docid);
    }

    function keep_alive() {
        Database_keep_alive($this->_cPtr);
    }

    function get_document($did) {
        $r=Database_get_document($this->_cPtr,$did);
        return is_resource($r) ? new Skjb_Search_Xapian_Document($r) : $r;
    }

    function get_spelling_suggestion($word,$max_edit_distance=2) {
        return Database_get_spelling_suggestion($this->_cPtr,$word,$max_edit_distance);
    }

    function spellings_begin() {
        $r=Database_spellings_begin($this->_cPtr);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function spellings_end() {
        $r=Database_spellings_end($this->_cPtr);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function synonyms_begin($term) {
        $r=Database_synonyms_begin($this->_cPtr,$term);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function synonyms_end($arg1) {
        $r=Database_synonyms_end($this->_cPtr,$arg1);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function synonym_keys_begin($prefix=null) {
        switch (func_num_args()) {
        case 0: $r=Database_synonym_keys_begin($this->_cPtr); break;
        default: $r=Database_synonym_keys_begin($this->_cPtr,$prefix);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function synonym_keys_end($prefix=null) {
        switch (func_num_args()) {
        case 0: $r=Database_synonym_keys_end($this->_cPtr); break;
        default: $r=Database_synonym_keys_end($this->_cPtr,$prefix);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function get_metadata($key) {
        return Database_get_metadata($this->_cPtr,$key);
    }

    function metadata_keys_begin($prefix=null) {
        switch (func_num_args()) {
        case 0: $r=Database_metadata_keys_begin($this->_cPtr); break;
        default: $r=Database_metadata_keys_begin($this->_cPtr,$prefix);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function metadata_keys_end($prefix=null) {
        switch (func_num_args()) {
        case 0: $r=Database_metadata_keys_end($this->_cPtr); break;
        default: $r=Database_metadata_keys_end($this->_cPtr,$prefix);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }
}